from math import sqrt

class vec:  
  def __init__ (self, x, y):
    self.x, self.y = x, y
  def __repr__ (self):
    return '(' + str(self.x) + ', ' + str(self.y) + ')'
    
  def __add__ (self, other): 
    return vec (self.x + other.x, self.y + other.y)
  def __sub__ (self, other):
    return vec (self.x - other.x, self.y - other.y)
  def __mul__ (self, a):
    return vec (self.x*a, self.y*a)

  def __iadd__ (self, other):
    self.x, self.y = self.x + other.x, self.y + other.y
    return self
  def __isub__ (self, other):
    self.x, self.y = self.x - other.x, self.y - other.y
    return self
  def __imul__ (self, other):
    self.x, self.y = self.x*a, self.y*a
    return self
  
  def dot (self, other):
    return self.x*other.x + self.y*other.y
  def mag_sq (self):
    return self.dot(self)
  def mag (self):
    return sqrt(self.dot(self))
  def set_mag (self, a):
    self *= a/self.mag()
  def unit (self):
    self.set_mag (1.)
    
